<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>设置软件价格策略</title>
<style type="text/css">
body {
	font-size:12px;
}
h1 {
	color: #494949;
	font-size: 25px;
	font-weight: 700;
	line-height: 1.1em;
}
label {
	color: #006600;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
	line-height: 120%;
}

label.pure {
	color: #111111;
	font-size: 12px;
}

input {
	font-size: 12px;
}

span.pl {
	color: #666666;
	font-size: 12px;
	line-height: 150%;
}

ul.errorMessage,ul.errorMessage li {
	margin: 0px;
	padding: 0px;
	font-size: 12px;
	color: #FF3300;
}

#wrapper {
	margin: 0 auto;
	width: 950px;
}

a {
	text-decoration: none;
	color: #336699;
}

a:hover {
	text-decoration: underline;
}
div.desc {
	padding: 5px 28px;
	color: #666666;
	font-size: 12px;
	line-height: 162%;
}
div.oper {
	padding: 5px 28px;
	border-bottom: 1px solid #EEEEEE;
}
table.price td {
	text-align:center;
}
input.number {
	text-align:right;
}
</style>
<script type="text/javascript">
var next = <s:property value="pricingStrategys.size()"/>;
function deletePricingStrategy(element) {
	element.parentNode.parentNode.parentNode.removeChild(element.parentNode.parentNode);
}
function addPricingStrategy() {
	next ++;
	
	var tr = document.getElementById("pricingStrategyTemplate").cloneNode(true);
	tr.id = "";
	tr.style.display = "";
	document.getElementById("pricingStrategyTemplate").parentNode.appendChild(tr);

	var inputs = tr.getElementsByTagName("INPUT");
	for (var i=0;i<inputs.length;i++) {
		if ("pricingStrategys_.price" == inputs[i].name) {
			inputs[i].id="savePricingStrategy_pricingStrategys_"+next+"__price";
			inputs[i].name="pricingStrategys["+next+"].price";
		}
		if ("pricingStrategys_.amount" == inputs[i].name) {
			inputs[i].id="savePricingStrategy_pricingStrategys_"+next+"__amount";
			inputs[i].name="pricingStrategys["+next+"].amount";
		}
		if ("pricingStrategys_.unit" == inputs[i].name) {
			inputs[i].id="savePricingStrategy_pricingStrategys_"+next+"__unit";
			inputs[i].name="pricingStrategys["+next+"].unit";
		}
	}

	var selects = tr.getElementsByTagName("SELECT");
	for (var i=0;i<selects.length;i++) {
		if ("pricingStrategys_.unit" == selects[i].name) {
			selects[i].id="savePricingStrategy_pricingStrategys_"+next+"__unit";
			selects[i].name="pricingStrategys["+next+"].unit";
		}
	}
}
</script>
<s:head />
</head>
<body>
<div id="wrapper">
<h1>设置<i><s:property value="software.name" /></i>的价格策略</h1>
<s:form action="savePricingStrategy">
	<s:hidden name="software.id" />
	<s:hidden name="software.pricingStrategyType" />
	<label>价格方案：</label><span class="pl">显示在软件列表页面，例如60元/2月，0.2元/1分钟 </span>
	<br />
	<s:fielderror />
	<br />
	<div class="desc">
	<table class="price" id="pricingStrategysTable">
		<tr>
			<td>价格</td>
			<td>/</td>
			<td>数量</td>
			<td>单位</td>
			<td></td>
		</tr>
		<tr id="pricingStrategyTemplate" style="display:none;">
			<td><s:textfield name="pricingStrategys_.price" maxlength="8" size="6" cssClass="number"/> 元</td>
			<td>/</td>
			<td><s:textfield name="pricingStrategys_.amount" maxlength="8" size="6" cssClass="number"/></td>
			<td><s:if test="software.pricingStrategyType==\"T\""><s:select name="pricingStrategys_.unit" list="#{'':'','M':'月','D':'天'}"/></s:if>
				<s:elseif test="software.pricingStrategyType==\"P\""><s:textfield name="pricingStrategys_.unit" maxlength="4" size="2"/></s:elseif></td>
			<td><input type="button" value="删除" onclick="deletePricingStrategy(this);"/></td>
		</tr>
		<s:if test="pricingStrategys.size()==0">
		<tr>
			<td><s:textfield name="pricingStrategys[0].price" maxlength="8" size="6" cssClass="number"/> 元</td>
			<td>/</td>
			<td><s:textfield name="pricingStrategys[0].amount" maxlength="8" size="6" cssClass="number"/></td>
			<td><s:if test="software.pricingStrategyType==\"T\""><s:select name="pricingStrategys[0].unit" list="#{'':'','M':'月','D':'天'}"/></s:if>
				<s:elseif test="software.pricingStrategyType==\"P\""><s:textfield name="pricingStrategys[0].unit" maxlength="4" size="2"/></s:elseif></td>
			<td><input type="button" value="删除" onclick="deletePricingStrategy(this);"/></td>
		</tr>
		</s:if> <s:else>
		<s:iterator value="pricingStrategys" id="pricingStrategy" status="st">
		<s:if test="#pricingStrategy != null">
		<tr>
			<td><s:textfield name="%{'pricingStrategys['+#st.index+'].price'}" maxlength="8" size="6" cssClass="number" value="%{price}"/> 元</td>
			<td>/</td>
			<td><s:textfield name="%{'pricingStrategys['+#st.index+'].amount'}" maxlength="8" size="6" cssClass="number" value="%{amount}"/></td>
			<td><s:if test="software.pricingStrategyType==\"T\""><s:select name="%{'pricingStrategys['+#st.index+'].unit'}" list="#{'':'','M':'月','D':'天'}"/></s:if>
				<s:elseif test="software.pricingStrategyType==\"P\""><s:textfield name="%{'pricingStrategys['+#st.index+'].unit'}" maxlength="4" size="2" value="%{unit}"/></s:elseif></td>
			<td><input type="button" value="删除" onclick="deletePricingStrategy(this);"/></td>
		</tr>
		</s:if>
		</s:iterator>
		</s:else>
	</table>
	</div>
	<div class="oper">
	<input type="button" value="增加" onclick="addPricingStrategy();"/>
	</div>
	<br />
	<s:submit value="保存设置" />
	<input type="button" value="取消" onclick="window.location.href='<s:url action="applist"/>';" />
</s:form></div>
</body>
</html>